//
//  InviteRankingViewController.m
//  PCR
//
//  Created by shumei on 16/7/11.
//  Copyright © 2016年 shumei. All rights reserved.
//

#import "InviteRankingViewController.h"
#import "InviteRankingHeaderView.h"
#import "InviteRankingTableViewCell.h"

@interface InviteRankingViewController ()<
UITableViewDelegate,
UITableViewDataSource
>
{
    UITableView * table_view;
}
@end

@implementation InviteRankingViewController


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [[YMBaseTabBarViewController shareInstance] setTabbarHidden];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTopTitleWithTitle:@"邀请排名"];
    [self setLeftItemWithTitle:nil OrImage:@"navLeftBtn.png"];
    [self creatTableView];
    //马上收徒
    [self creatInviteButton];
}

-(void)creatTableView
{
    table_view = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,MainSCreen.width , MainSCreen.height - nav_Height - 50) style:UITableViewStylePlain];
    table_view.delegate = self;
    table_view.dataSource = self;
    [table_view setTableFooterView:[[UIView alloc] init]];
    [self.view addSubview:table_view];
}
#pragma mark ---------------------------------UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 2)
    {
        return 10;
    }
    else if (section == 0)
    {
        return 0;
    }
    return 1;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
{
    return 3;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
    {
        return TableView_Default_RowHight;
    }
    return 0.1f;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 2)
    {
        return 0.1f;
    }
    return TableView_Default_SectionHight;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 2)
    {
        if (indexPath.row != 0)
        {
            return 60;
        }
    }
    return TableView_Default_RowHight;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0)
    {
        InviteRankingHeaderView * headerView = [[InviteRankingHeaderView alloc]initWithFrame:CGRectMake(0, 0, MainSCreen.width / 2, TableView_Default_RowHight)];
        
        return headerView;
    }
    
    return nil;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * First_Cell = @"First_Cell";
    static NSString * Second_Cell = @"Second_Cell";
    static NSString * Third_Cell = @"Third_Cell";
    //我的邀请：＊＊人，累计收入＊＊，全国排名＊＊
    if (indexPath.section == 1)
    {
        InviteRankingTableViewCell *cell = [[NSBundle mainBundle]loadNibNamed:@"InviteRankingTableViewCell" owner:self options:nil][0];
        if (!cell)
        {
            cell = [[InviteRankingTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:First_Cell];
            
        }
        
        return cell;
    }
    //名次，邀请人数，累计收入
    else if (indexPath.section == 2)
    {
        if (indexPath.row == 0)
        {
            InviteRankingTableViewCell *cell = [[NSBundle mainBundle]loadNibNamed:@"InviteRankingTableViewCell" owner:self options:nil][1];
            if (!cell)
            {
                cell = [[InviteRankingTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:Second_Cell];
                
            }
            
            return cell;
        }
        //详情
        InviteRankingTableViewCell *cell = [[NSBundle mainBundle]loadNibNamed:@"InviteRankingTableViewCell" owner:self options:nil][2];
        if (!cell)
        {
            cell = [[InviteRankingTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:Third_Cell];
            
        }
        
        return cell;

    }
    return nil;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
}

#pragma mark ---------------------------------马上收徒
-(void)creatInviteButton
{
    UIButton * button = [UIButton buttonWithType:0];
    button.frame = CGRectMake(15, table_view.frame.size.height, MainSCreen.width - 30, 40);
    button.layer.cornerRadius = 5;
    button.layer.masksToBounds = YES;
    [button setTitle:@"马上收徒" forState:0];
    button.titleLabel.font = [UIFont systemFontOfSize:16.0];
    button.backgroundColor = [UIColor orangeColor];
    [button addTarget:self action:@selector(BtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}
-(void)BtnClick:(UIButton *)btn
{
    
}


-(void)routerEventWithName:(NSString *)eventName userInfo:(NSDictionary *)userInfo
{
    
    [table_view reloadData];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
